package com.java110.mall.shop.bmo.shopReturnAddress.impl;

import com.java110.dto.shop.ShopReturnAddressDto;
import com.java110.intf.shop.IShopReturnAddressInnerServiceSMO;
import com.java110.mall.shop.bmo.shopReturnAddress.IGetShopReturnAddressBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("getShopReturnAddressBMOImpl")
public class GetShopReturnAddressBMOImpl implements IGetShopReturnAddressBMO {

    @Autowired
    private IShopReturnAddressInnerServiceSMO shopReturnAddressInnerServiceSMOImpl;

    /**
     * @param shopReturnAddressDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(ShopReturnAddressDto shopReturnAddressDto) {


        int count = shopReturnAddressInnerServiceSMOImpl.queryShopReturnAddresssCount(shopReturnAddressDto);

        List<ShopReturnAddressDto> shopReturnAddressDtos = null;
        if (count > 0) {
            shopReturnAddressDtos = shopReturnAddressInnerServiceSMOImpl.queryShopReturnAddresss(shopReturnAddressDto);
        } else {
            shopReturnAddressDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) shopReturnAddressDto.getRow()), count, shopReturnAddressDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
